import { request } from ".";

import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'

request.interceptors.request.use((config) => {
    nprogress.start()
    config.headers.userTempId = store.state.user.userTempId
    config.headers.token = store.state.user.token
    return config
})

request.interceptors.response.use((response) => {
    if (response.data.code === 200) {
        nprogress.done()
        return response.data.data
    } else {
        nprogress.done()
        return Promise.reject({ message: response.data.message })
    }

}, (error) => {
    return Promise.reject(error)
})

export default request